<?php
/*
 * Класс держит в Items массив вариантов размеров (массив Admin_Model_GalleryItem) одной и той же картинки.
 */
class Admin_Model_Image{
	public $ThumbID;
	public $Items;
    private static $_galleryItemMappper;
    public static function getGalleryItemMapper(){
        if (null==self::$_galleryItemMappper){
            self::$_galleryItemMappper = new Admin_Model_GalleryItemMapper();
        }
        return self::$_galleryItemMappper;
    }


    public function getImageBySizeId($sizeId){
		foreach ($this->Items as $i){
			if ($i->getSizeId()==$sizeId)
				return $i;
		}
        return self::getGalleryItemMapper()->find($this->getId(),$sizeId);
	}
    public function getId(){
        if (null==$this->Items)
            throw new Zend_Exception("Items is null");
        return $this->Items[0]->getId();
    }
    
    function __clone(){
        if ((null==$this->Items) || (0==count($this->Items)))
            return;
        $m = new Admin_Model_GalleryItemMapper();
		$this->Items = $m->cloneImage($this->getId());
    }
    
    /*public function getFileName($sizeId){
        $i = $this->getImageBySizeId($sizeId);
        if ($i==null) return "";
        return $i->getId().'_'.$sizeId.'_'.$this->getWidth().'x'.$i->getHeight().'.'.$i->getExt();
    }*/
}
?>